import Vue from 'vue'
import Router from 'vue-router'
// import Home from ''
import Home from './components/home.vue'
import Login from './components/login.vue'
import showData from './components/showData.vue'
import ledShow from './components/ledShow.vue'
// import AcquisitionTask from './components/AcquisitionTask.vue'
// import MergeRequestList from './components/MergeRequestList.vue'
// import CommitSHA from './components/CommitSHAlist.vue'
// import PackagesList from './components/PackagesList.vue'
// import PipelineDetailpage from './components/PipelineDetailpage.vue'
// import MergeRequestPage from './components/MergeRequestPage.vue'
// import CommitSHAPage from './components/CommitSHAPage.vue'
// import TestCase from './components/TestCase.vue'
// import TestCasePage from './components/TestCasePage.vue'
// import ProblemFix from './components/ProblemFix.vue'
// // import ProblemFixPage from './components/ProblemFixPage.vue'
// import ProblemFixPage from './components/ProblemFixPage .vue'

// 解决问题NavigationDuplicated: Avoided redundant navigation to current location: "/2"
const originalPush = Router.prototype.push

Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      // redirect:'/1',
      name: 'Home',
      component: Home
      // children:[
      //   {
      //     path: '/1',
      //     name: 'AcquisitionTask',
      //     component: AcquisitionTask,
      //   },
      //   {
      //     path: '/2',
      //     name: 'MergeRequestList',
      //     component: MergeRequestList,
      //   },
      //   {
      //     path: '/3',
      //     name: 'CommitSHA',
      //     component: CommitSHA,
      //   },
      //   {
      //     path: '/4',
      //     name: 'PackagesList',
      //     component: PackagesList,
      //   },
      //   {
      //     path: '/5',
      //     name: 'TestCase',
      //     component: TestCase,
      //   }, {
      //     path: '/5-1',
      //     name: 'TestCasePage',
      //     component: TestCasePage,
      //   },
      //   {
      //     path: '/1-1',
      //     name: 'PipelineDetailpage',
      //     component: PipelineDetailpage,
      //   },
      //   {
      //     path: '/2-1',
      //     name: 'MergeRequestPage',
      //     component: MergeRequestPage,
      //   },
      //   {
      //     path: '/3-1',
      //     name: 'CommitSHAPage',
      //     component: CommitSHAPage,
      //   },
      //   {
      //     path: '/6',
      //     name: 'ProblemFix',
      //     component: ProblemFix,
      //   },
      //   {
      //     path: '/6-1',
      //     name: 'ProblemFixPage',
      //     component: ProblemFixPage,
      //   },
      // ]
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },
    {
      path: '/ledShow',
      name: 'ledShow',
      component: ledShow
    },
    {
      path: '/showData',
      name: 'showData',
      component: showData
    },
  ]
})
router.beforeEach((to, from, next) => {
  // 如果不是首页，进行存储
  // 登陆后拿到存储路径，跳转
  // console.log('frompath',from.path)
  // console.log('topath',to.fullPath)
  // if(to.fullPath!='/1'&&localStorage.getItem('fullpath')!='/1'){
  //   localStorage.setItem('fullPath',to.fullPath)
  // }
  // if (from.path !='/' && to.path =='/1'){
  //   localStorage.setItem('fullPath',to.fullPath)
  // }

  if (to.path == '/' && !window.localStorage.getItem('userName')) {
    next({
      path: '/login'
    })
  } else {
    // 不进行拦截
    next()
  }
})
export default router
